package com.example.backblog.advicer;

import cn.hutool.json.JSONUtil;
import com.example.backblog.exception.user.VerifyException;
import com.example.backblog.vo.ApiResult;
import org.hibernate.service.spi.ServiceException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@ControllerAdvice
public class GlobalException {
    @ExceptionHandler(ServiceException.class)
    public ResponseEntity serviceException(ServiceException e) {
        e.printStackTrace();
        return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
    @ExceptionHandler(VerifyException.class)
    @ResponseBody
    public ResponseEntity verifyException(VerifyException e) {
        e.printStackTrace();
        return ResponseEntity.internalServerError().body(ApiResult.error(501, e.getMessage(), null));

    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseEntity globalException(Exception e){
        e.printStackTrace();
        return ResponseEntity.internalServerError().body(ApiResult.error(500, e.getMessage(), null));
//        return ApiResult.error(500, e.getMessage(), null);
    }
}
